
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[spSchedule_GetSchedule]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
	DROP PROCEDURE [dbo].[spSchedule_GetSchedule]
GO

GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Eric Liew
-- Create date: 6/2/2009
-- Description:	Get a Plate
-- =============================================
CREATE PROCEDURE [dbo].[spSchedule_GetSchedule]
(
		@scheduleId INT
)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON

select schedule.ScheduleId,
		Schedule.ShiftId,
		ScheduleDate,
		ScheduleDriverTaxi.DriverId,
		ScheduleDriverTaxi.TaxiId,
		ScheduleDriverTaxi.ScheduleDriverTaxiId,
		Plate.PlateNumber,
		Shift.ShiftDescription,		
		Driver.FirstName,
		Driver.LastName, 
		Driver.FirstName + ' ' + Driver.LastName AS [Name]
From Schedule
	INNER JOIN ScheduleDriverTaxi
		ON Schedule.ScheduleId = ScheduleDriverTaxi.ScheduleId
	INNER JOIN Shift
	    ON Shift.ShiftId = Schedule.ShiftId
	INNER JOIN Taxi
		ON Taxi.TaxiId = ScheduleDriverTaxi.TaxiId
	INNER JOIN Plate
	    ON Plate.PlateId = Taxi.PlateId
	LEFT JOIN Driver
		ON ScheduleDriverTaxi.DriverId = Driver.DriverId
Where Schedule.ScheduleId = @scheduleId 

END
GO
